// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0


import { TextEdit } from "std-widgets.slint";
export component TestCase inherits Window {
    width: 100px;
    height: 100px;
    edit := TextEdit {
        width: 100%;
        height: 100%;
    }

    forward-focus: edit;
    out property <bool> textedit-focused <=> edit.has_focus;
    callback edited <=> edit.edited;
    in-out property <string> text <=> edit.text;
    in-out property <bool> read-only <=> edit.read-only;
    public function paste() {
        edit.paste();
    }
}

/*


```rust
use std::cell::RefCell;
use std::rc::Rc;
use slint::SharedString;

let instance = TestCase::new().unwrap();

let edits = Rc::new(RefCell::new(Vec::new()));
instance.on_edited({
    let edits = edits.clone();
    move |val| {
    edits.borrow_mut().push(val);
}});

slint_testing::send_mouse_click(&instance, 25., 25.);
assert!(instance.get_textedit_focused());
assert!(edits.borrow().is_empty());

slint_testing::send_keyboard_string_sequence(&instance, "hello");
assert_eq!(edits.borrow().clone(), vec!["h", "he", "hel", "hell", "hello"]);


// Test mouse cursor for issue 6444
use slint::{LogicalPosition, platform::{WindowEvent, PointerEventButton}};
use slint::private_unstable_api::re_exports::MouseCursor;
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Text, "after previous click");
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(50.0, 50.0), button: PointerEventButton::Middle });
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Text, "Middle button pressed");
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(50.0, 50.0), button: PointerEventButton::Middle });
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Text, "Middle button released");
instance.window().dispatch_event(WindowEvent::PointerExited { });
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Default);

// test page up/down
for x in 0..10 {
    slint_testing::send_keyboard_string_sequence(&instance, &format!("\nThis is line {x}"));
}
slint_testing::send_keyboard_string_sequence(&instance, "\nEnd");
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::PageUp));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::PageUp));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::PageUp));
slint_testing::send_keyboard_string_sequence(&instance, "Begin!");
assert_eq!(instance.get_text(), "Begin!hello\nThis is line 0\nThis is line 1\nThis is line 2\nThis is line 3\nThis is line 4\nThis is line 5\nThis is line 6\nThis is line 7\nThis is line 8\nThis is line 9\nEnd");
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::PageDown));
slint_testing::send_keyboard_string_sequence(&instance, "XX");
let test = instance.get_text();
// The exact position depends on the size of the content which depends on the style, but it should be in the middle
assert!(test.contains("\nThis iXXs line"));

// use the menu key to pen the menu and choose select call
instance.set_text("Hello👋".into());
assert_eq!(instance.get_text(), "Hello👋");
// select all
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::Menu));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::UpArrow));
slint_testing::send_keyboard_string_sequence(&instance, "\n");
assert_eq!(instance.get_text(), "Hello👋");
// copy
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::Menu));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(slint::platform::Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, "\n");
assert_eq!(instance.get_text(), "Hello👋");

slint_testing::send_keyboard_string_sequence(&instance, "Xxx");
assert_eq!(instance.get_text(), "Xxx");
instance.invoke_paste();
assert_eq!(instance.get_text(), "XxxHello👋");

let mut edit_search = slint_testing::ElementHandle::find_by_element_id(&instance, "TestCase::edit");
let edit = edit_search.next().unwrap();
assert_eq!(edit.accessible_read_only(), Some(false));
instance.set_read_only(true);
assert_eq!(edit.accessible_read_only(), Some(true));
```

*/
